//
//  HMReetweetView.m
//  OC新浪微博
//
//  Created by wyman on 16/4/19.
//  Copyright © 2016年 wyman. All rights reserved.
//

#import "HMReetweetView.h"
#import "HMStatusPictureView.h"
#import <Masonry.h>
@interface HMReetweetView()
@property (nonatomic, strong) UIButton *bkgButton;

@property (nonatomic, strong) UILabel *textLabel;

@property (nonatomic, strong) HMStatusPictureView *pictureView;

@end
@implementation HMReetweetView


//创建转发页面
-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self prepareUI];
    }
    return self;
}

//给数据赋值
-(void)setRetweet:(HMStatu *)retweet
{
    _retweet = retweet;
    
    
    NSString *retName = retweet.user.screen_name;
    NSString *text = retweet.text;
    
    NSString *labeltext =  [NSString stringWithFormat:@"@%@: %@",retName,text];

    self.textLabel.text = retweet != nil ? labeltext : nil;
    
    
//    HMLog(@"%@",text);

    
    self.pictureView.pictureURLs = retweet.storePictureURLs;

//    retweetPictureView.snp_updateConstraints { (make) -> Void in
//        let margin = retweetStatus?.storePicutreURLs == nil ? 0 : HMStatusCellMargin
//        make.top.equalTo(retweetLabel.snp_bottom).offset(margin)

    [self.pictureView mas_updateConstraints:^(MASConstraintMaker *make) {
        CGFloat Marin = retweet.storePictureURLs == nil ? 0 : 8;
        
        make.top.equalTo(self.textLabel.mas_bottom).offset(Marin);
    }];

}


-(void)prepareUI{

//添加按钮,图片,文字,
    [self addSubview:self.bkgButton];
    [self addSubview:self.textLabel];
    [self addSubview:self.pictureView];
    
    //设置约束
    [self.bkgButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    //设置文字约束
    [self.textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.top.equalTo(self).offset(8);
        make.trailing.equalTo(self).offset(-8);
    }];
    
    //设置图片约束
    [self.pictureView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self).offset(8);
        make.top.equalTo(self.textLabel.mas_bottom).offset(8);
//        make.size.mas_equalTo(CGRectZero);
        make.size.mas_equalTo(CGSizeMake(10, 10));
       
    }];

    [self mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.pictureView).offset(8);
    }];
    
    
}

/**
 *  懒加载
 */
-(UIButton *)bkgButton{
    if (_bkgButton == nil) {
        _bkgButton = [[UIButton alloc]init];
        [_bkgButton setBackgroundImage:[UIImage imageNamed:@"retweet_background"] forState:UIControlStateNormal];
        [_bkgButton setBackgroundImage:[UIImage imageNamed:@"retweet_background_highlighted"] forState:UIControlStateHighlighted];
    }

    return _bkgButton;
}

-(UILabel *)textLabel{
    if (_textLabel == nil) {
        _textLabel = [[UILabel alloc]init];
        _textLabel.numberOfLines = 0;
        _textLabel.font = [UIFont systemFontOfSize:15];
        _textLabel.textColor = [UIColor darkGrayColor];
//        _textLabel.backgroundColor = [UIColor darkGrayColor];
    }
    return _textLabel;
}

-(HMStatusPictureView *)pictureView{
    if (_pictureView == nil) {
        _pictureView = [[HMStatusPictureView alloc]init];
    }
    return _pictureView;
}

@end
